package com.xhs.controller;

import com.xhs.util.ProxyTestUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 代理测试控制器
 *
 * @author xhs
 */
@Slf4j
@RestController
@RequestMapping("/api/proxy")
@Tag(name = "代理测试", description = "代理功能测试接口")
public class ProxyTestController {

    @Autowired
    private ProxyTestUtil proxyTestUtil;

    /**
     * 测试代理连接
     */
    @Operation(summary = "测试代理连接", description = "测试代理是否正常工作")
    @GetMapping("/test")
    public ResponseEntity<Map<String, Object>> testProxy() {
        Map<String, Object> result = new HashMap<>();
        
        boolean isSuccess = proxyTestUtil.testProxy();
        
        result.put("success", isSuccess);
        result.put("message", isSuccess ? "代理连接测试成功" : "代理连接测试失败");
        
        return ResponseEntity.ok(result);
    }

    /**
     * 获取代理IP信息
     */
    @Operation(summary = "获取代理IP信息", description = "获取当前使用的代理IP地址")
    @GetMapping("/ip")
    public ResponseEntity<Map<String, Object>> getProxyIp() {
        Map<String, Object> result = new HashMap<>();
        
        String ipInfo = proxyTestUtil.getProxyIpInfo();
        
        result.put("success", true);
        result.put("ipInfo", ipInfo);
        result.put("message", "获取代理IP信息成功");
        
        return ResponseEntity.ok(result);
    }
} 